#democracy
cs_result_1 <- att_gt(
  yname = "avg_score_democ_support",           # outcome variable
  tname = "A",        # time variable
  idname = "ID",         # unit identifier
  gname = "g_did",           # first period treated (0 if never treated)
  xformla = ~1,          # no covariates; include covariates like ~X1 + X2 if needed
  data = estimation_data,
  panel = TRUE           # TRUE since this is panel data
)


#trust in elections
cs_result_2 <- att_gt(
  yname = "avg_score_trust_elect",           # outcome variable
  tname = "A",        # time variable
  idname = "ID",         # unit identifier
  gname = "g_did",           # first period treated (0 if never treated)
  xformla = ~1,          # no covariates; include covariates like ~X1 + X2 if needed
  data = estimation_data,
  panel = TRUE           # TRUE since this is panel data
)


#outgroup animosity - politics
cs_result_3 <- att_gt(
  yname = "avg_score_dislike_pol",           # outcome variable
  tname = "A",        # time variable
  idname = "ID",         # unit identifier
  gname = "g_did",           # first period treated (0 if never treated)
  xformla = ~1,          # no covariates; include covariates like ~X1 + X2 if needed
  data = estimation_data,
  panel = TRUE           # TRUE since this is panel data
)


#outgroup animosity - ethnicity
cs_result_4 <- att_gt(
  yname = "avg_score_dislike_group",           # outcome variable
  tname = "A",        # time variable
  idname = "ID",         # unit identifier
  gname = "g_did",           # first period treated (0 if never treated)
  xformla = ~1,          # no covariates; include covariates like ~X1 + X2 if needed
  data = estimation_data,
  panel = TRUE           # TRUE since this is panel data
)



p1 <-
  ggdid(cs_result_1) +
  theme_bw() + 
  scale_color_manual(values = c("darkgrey", "black")) +
  scale_x_continuous(breaks = c(1, 2), labels = c("Pre-Election", "Post-Election")) +
  ylab("Effect of Losing on Outcome") +
  ggtitle("Support for Democracy") +
  theme(strip.text = element_blank(),
        legend.position = "none")

p2 <-
  ggdid(cs_result_2) +
  theme_bw() + 
  scale_color_manual(values = c("darkgrey", "black")) +
  scale_x_continuous(breaks = c(1, 2), labels = c("Pre-Election", "Post-Election")) +
  ylab("Effect of Losing on Outcome") +
  ggtitle("Trust in Elections") +
  theme(strip.text = element_blank(),
        legend.position = "none")

p3 <-
  ggdid(cs_result_3) +
  theme_bw() + 
  scale_color_manual(values = c("darkgrey", "black")) +
  scale_x_continuous(breaks = c(1, 2), labels = c("Pre-Election", "Post-Election")) +
  ylab("Effect of Losing on Outcome") +
  ggtitle("Partisan Animosity") +
  theme(strip.text = element_blank(),
        legend.position = "none")


p4 <-
  ggdid(cs_result_4) +
  theme_bw() + 
  scale_color_manual(values = c("darkgrey", "black")) +
  scale_x_continuous(breaks = c(1, 2), labels = c("Pre-Election", "Post-Election")) +
  ylab("Effect of Losing on Outcome") +
  ggtitle("Ethnic Animosity") +
  theme(strip.text = element_blank(),
        legend.position = "none")



pre_plot <- ggarrange(p1, p2, p3, p4, ncol = 2, nrow = 2)


ggsave(plot = pre_plot, "./outputs/figures/figure_a9.pdf", width = 8, height = 4)
ggsave(plot = pre_plot, "./outputs/figures/figure_a9.eps", device = "eps", width = 8, height = 4)

